<?php
//抽象中介者类
abstract class Mediator{
    abstract public function send($message,$colleague);
}

abstract class Colleague{
    protected $mediator;

    public function __construct($mediator)
    {
        $this->mediator = $mediator;
    }
}

class ConcreteMediator extends Mediator{
    public $concreteColleague1;
    public $concreteColleague2;

    public function send($message, $colleague)
    {
       if($colleague == $this->concreteColleague1){
           $this->concreteColleague1->notify();
       }else{
           $this->concreteColleague2->notify();
       }
    }
}

//具体同事对象
class ConcreteColleague1 extends Colleague{
    public function send($message){
        $this->mediator->send($message,$this);
    }

    public function notify(){
        echo '同事1得到消息';
    }
}

class ConcreteColleague2 extends Colleague{
    public function send($message){
        $this->mediator->send($message,$this);
    }

    public function notify(){
        echo '同事2得到消息';
    }
}

//客户端
$mediator = new ConcreteMediator();
$ts1 = new ConcreteColleague1($mediator);
$ts2 = new ConcreteColleague2($mediator);
$mediator->concreteColleague1 = $ts1;
$mediator->concreteColleague2 = $ts2;

/*var_dump($mediator->concreteColleague1);*/

$ts1->send('吃过饭了吗');
$ts2->send('没呢，你打算请客吗？');